'use strict';
/**
 * 创建 用户迁移文件
 * @type {import('sequelize-cli').Migration}
 * */
module.exports = {
	async up(queryInterface, Sequelize) {
		await queryInterface.createTable('Users', {
			id: {
				allowNull: false,
				autoIncrement: true,
				primaryKey: true,
				type: Sequelize.INTEGER.UNSIGNED
			},
			email: {
				allowNull: false,
				type: Sequelize.STRING
			},
			username: {
				allowNull: false,
				type: Sequelize.STRING
			},
			password: {
				allowNull: false,
				type: Sequelize.STRING
			},
			nickname: {
				type: Sequelize.STRING
			},
			sex: {
				allowNull: false,
				type: Sequelize.TINYINT
			},
			company: {
				type: Sequelize.STRING
			},
			introduce: {
				type: Sequelize.TEXT
			},
			role: {
				allowNull: false,
				defaultValue: 0,
				type: Sequelize.TINYINT
			},
			createdAt: {
				allowNull: false,
				type: Sequelize.DATE
			},
			updatedAt: {
				allowNull: false,
				type: Sequelize.DATE
			}
		});
	},
	async down(queryInterface, Sequelize) {
		await queryInterface.addIndex('Users', {
			fields: ['email'], // 索引字段
			unique: true // 唯一索引
		});
		await queryInterface.addIndex('Users', {
			fields: ['username'], // 索引字段
			unique: true // 唯一索引
		});
		await queryInterface.addIndex('Users', {
			fields: ['role'], // 索引字段
		});
	}
};